import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wanxiang_app/bean/normal_entity.dart';
import 'package:wanxiang_app/bean/tousu_entity.dart';
import 'package:wanxiang_app/utils/constant.dart';
import '../../bean/service_list_entity.dart';
import '../../utils/network_manager.dart';
import '../../utils/network_url.dart';
import '../../utils/toast_util.dart';
import '../../widgets/myappbar.dart';
import 'package:get/get.dart';
import 'package:flutter/services.dart';

class TousuController extends GetxController{

  @override
  void onInit() {
    super.onInit();
    _getService();
  }
  @override
  void onClose() {
    super.onClose();
  }
  List<TousuData> list = [];
  void _getService(){
    DioManager.getInstance().post(ServiceUrl.tousu,null, (data) async {
      TousuEntity bannerEntity = TousuEntity.fromJson(jsonDecode(data));
      list = bannerEntity.data;
      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }
}


class TousuPage extends GetView<TousuController>  {
  late TousuController controller ;
  late BuildContext context ;
  @override
  Widget build(BuildContext context1) {
    Get.lazyPut<TousuController>(() => TousuController());
    controller = Get.find();
    context = context1;

    return GetBuilder<TousuController>(
      builder: (_){
        return  Scaffold(
            appBar: MyAppBar(context: context, title: '投诉建议',hasLeading: true,),
            backgroundColor: Color(0xFFF7F8FC),
            body:_content());
      },
    )
    ;

  }
  Widget _content(){
    return SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.only(left: 20.w,top: 20.h,right: 20.w,bottom: 20.h),
          child: Column(
            children: _all(),
          ),
        )
    ) ;
  }

  List<Widget> _all(){
    List<Widget> aa =[];
    for(int i = 0;i<controller.list.length;i++){
      aa.add(_item(controller.list[i]));
    }
    return aa;
  }


  Widget _item(item){
    return Container(
      height: 238.h,
      alignment: Alignment.center,
      margin: EdgeInsets.all(16.h),
      decoration: BoxDecoration(
        color: Colors.white,

      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Image.asset(Constant.IMG_BASE+'tousu.png',width: 48.w,height: 48.h,),
          SizedBox(height: 17.h,),
          Text(item.title),
          SizedBox(height: 8.h,),
          InkWell(
              onTap: (){
                Clipboard.setData(ClipboardData(text: item.content));
                ToastUtil.show('复制成功');
              },
            child:    Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(item.content),
                SizedBox(width: 5.w,),
                Image.asset(Constant.IMG_BASE+'copy.png',width: 9.w,height: 9.h,)

              ],
            )
          )


        ],
      ),
    );
  }







}